program iri2gim
    CHARACTER*100 filename
    REAL lat, lon
    REAL lat_from, lat_to, lat_step
    REAL lon_from, lon_to, lon_step
    REAL tec, tecb, tect
    REAL hbeg, hend
    INTEGER lat_steps, lon_steps, doy_from, doy_to, hour_from, hour_to
    INTEGER year, doy, hour
    logical   JF(50)
    dimension  outf(20,1000),OARR(100)
    INTEGER JMAG
    
    call read_ig_rz
    call readapf107
    
    do i=1,100
        OARR(i)=-1.0
    enddo
    
    do i=1,50 
        jf(i)=.true.
    enddo
    


!          jf(1)=.false.      ! f=no electron densities (t) 
!          jf(2)=.false.      ! f=no temperatures (t)
!          jf(3)=.false.      ! f=no ion composition (t)
          jf(4)=.false.      ! t=B0table f=other models (f)
          jf(5)=.false.      ! t=CCIR  f=URSI foF2 model (f)
          jf(6)=.false.      ! t=DS95+DY85   f=RBV10+TBT15 (f)
!          jf(7)=.false.      ! t=tops f10.7<188 f=unlimited (t)
!          jf(19)=.false. 	 !F1 prob model   only if foF1>0 and not NIGHT (t)
!          jf(20)=.false.     !standard F1  standard F1 plus L condition  (t)
! (19,20) = (t,t) f1-prob, (t,f) f1-prob-L, (f,t) old F1, (f,f) no F1
          jf(21)=.false.     ! t=ion drift computed f=not comp.(f)
!          jf(22)=.false.     ! ion densities in m-3 (t)
          jf(23)=.false.     ! t=AEROS/ISIS f=TTS Te with PF10.7 (f)
!          jf(24)=.false.     ! t=D-reg-IRI-1990 f=FT-2001 (t)
!		   jf(25)=.false.     ! t=F107D from APF107.DAT  f=user (t)
!          jf(26)=.false.	 ! t=STORM model on   f= off (t)
          jf(28)=.false.	 ! t=spread-F computed f=not comp. (f)
          jf(29)=.false.     ! t=old  f=New Topside options (f)
          jf(30)=.false.     ! t=corr f=NeQuick topside (f)
! (29,30) = (t,t) IRIold, (f,t) IRIcor, (f,f) NeQuick, (t,f) COR2
!          jf(31)=.false.     ! t=B0ABT f=Gulyaeva (t)
!		   jf(32)=.false.     ! t=F107_81 from APF107.DAT  f=user (t)
          jf(33)=.false. 	  ! t=auroral boundary   f=off (f)
!          jf(34)=.false. 	  ! t=messages on f= off (t)
          jf(35)=.false. 	  ! t=auroral E-storm model on f=off (f)
!          jf(36)=.false. 	  ! t=hmF2 w/out foF2_storm f=with (t)
!          jf(37)=.false. 	  ! t=topside w/out foF2_storm f=with (t)
!          jf(38)=.false. 	  ! t=WRITEs off in IRIFLIP f=on (t)
          jf(39)=.false. 	  ! t=M3000F2 model f=new hmF2 models (f)
    jf(40)=.false. 	  ! t=AMTB-model, f=Shubin-COSMIC model (f) 
!          jf(41)=.false. 	  ! t:COV=F10.7_386 f:COV=f(IG12) (t) 
!          jf(42)=.false. 	  ! t/f=Te w/o PF10.7 dependance (t)
!          jf(43)=.false. 	  ! t= B0 model f= B0 user input (t)
!          jf(44)=.false. 	  ! t= B1 model f= B1 user input (t)
!          jf(45)=.false. 	  ! t=HNEA=65/80 f=user input oarr(89)
!          jf(46)=.false. 	  ! t=HNEE=2000  f=user input oarr(90)
    jf(47)=.false. 	  ! t=CGM on  f=CGM off
        
    JMAG = 0
    
    year = 2019
    lat_from = 40. !-87.5
    lat_to = 87.5
    lat_step = 2.5
    lat_steps = (lat_to - lat_from)/lat_step

    lon_from = 20. !-180.
    lon_to = 180.
    lon_step = 5
    lon_steps = (lon_to - lon_from)/lon_step

    doy_from = 1
    doy_to = 2
    hour_from = 0
    hour_to = 24
    
    hbeg = 100
    hend = 2000
    hstp = hend-hbeg
    tec = -999.
    tect = -999.
    tecb = -999.
    iut = 1 !0:LT, 1:UT
    ivar = 1 !1/2/../8 for height/lat/long/year/month/day/day of year/hour)'
    do doy = doy_from, doy_to
        do hour = hour_from, hour_to
            write(filename,'(A,I3.3,A,I2.2,A)') 'out/iri',doy,'0.',19,'I'

            open(1, file=filename)
            do ilat = 0, lat_steps
                ALATI = lat_from + ilat*lat_step
                imd = -1
                do ilon = 0, lon_steps
                    ALONG = lon_from + ilon*lon_step
                    ! write(*,*) JMAG, ALATI, ALONG, YEAR, imd, hour, hbeg, hend, hstp
                    !call IRI_SUB(JF,JMAG,ALATI,ALONG,year,imd,hour, hbeg,hend,hstp,OUTF,OARR)
                    !call iri_tec (hbeg,hend,2,tec,tect,tecb)
                    call iri_web(JMAG,JF,ALATI,ALONG,year,mmdd,iut,hour, hbeg,hend,ivar,hbeg,hend,hstp,OUTF,OARR)
                    write(*,*) ALATI, ALONG, OARR
                    EXIT
                enddo
                EXIT
            enddo
            close(1)
            EXIT
        enddo
    enddo

endprogram iri2gim


